import XtxCity from "@/components/library/xtxCity";
import "./index.scss";
import { useState } from "react";
function GoodsName({ goods }: { goods: any }) {
  // 没登录
  const [provinceCode, setprovinceCode] = useState("110000");
  const [cityCode, setcityCode] = useState("119900");
  const [countyCode, setcountyCode] = useState("110101");
  const [fullLocation, setfullLocation] = useState("北京市 市辖区 东城区");
  if (goods.userAddresses) {
    const defaultAddress = goods.userAddresses.find(
      (item: any) => item.isDefault === 1
    );
    if (defaultAddress) {
      setprovinceCode(defaultAddress.provinceCode);
      setcityCode(defaultAddress.cityCode);
      setcountyCode(defaultAddress.countyCode);
      setfullLocation(defaultAddress.fullLocation);
    }
  }
  const changeFn = function (playload: any) {
    console.log(playload);

    setprovinceCode(playload.provinceCode);
    setcityCode(playload.cityCode);
    setcountyCode(playload.countyCode);
    setfullLocation(playload.fullLocation);
  };
  return (
    <>
      <p className="g-name">{goods.name}</p>
      <p className="g-desc">{goods.desc}</p>
      <p className="g-price">
        <span>{goods.price}</span>
        <span>{goods.oldPrice}</span>
      </p>
      <div className="g-service">
        <dl>
          <dt>促销</dt>
          <dd>12月好物放送，App领券购买直降120元</dd>
        </dl>
        <dl>
          <dt>配送</dt>
          <dd>
            至 <XtxCity change={changeFn} fullLocation={fullLocation}></XtxCity>
          </dd>
        </dl>
        <dl>
          <dt>服务</dt>
          <dd>
            <span>无忧退货</span>
            <span>快速退款</span>
            <span>免费包邮</span>
            <a href="javascript:;">了解详情</a>
          </dd>
        </dl>
      </div>
    </>
  );
}
export default GoodsName;
